package org.linlinjava.litemall.db.service;

import org.apache.commons.lang3.StringUtils;
import org.linlinjava.litemall.db.dao.LitemallOrderInvoiceMapper;
import org.linlinjava.litemall.db.domain.LitemallOrderInvoice;
import org.linlinjava.litemall.db.domain.LitemallOrderInvoiceExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LitemallOrderInvoiceService {

    @Resource
    private LitemallOrderInvoiceMapper orderInvoiceMapper;

    //增加
    public void addOrderInvoice(LitemallOrderInvoice orderInvoice){
        orderInvoiceMapper.insertSelective(orderInvoice);
    }
    //删除 ID
    public void delOrderInvoice(Integer id){
        orderInvoiceMapper.deleteByPrimaryKey(id);
    }
    //改
    public void updateOrderInvoice(LitemallOrderInvoice orderInvoice){
        orderInvoiceMapper.updateByPrimaryKeySelective(orderInvoice);
    }
    //查  多条件  添加时间倒序排列
    public List<LitemallOrderInvoice> findOrderInvoiceList(Integer userId,String orderSn ,Integer defaultInvoiceInt,String invoiceType){
       // PageHelper.startPage(page,pageSize);
        LitemallOrderInvoiceExample example = new LitemallOrderInvoiceExample();
        LitemallOrderInvoiceExample.Criteria criteria = example.createCriteria();
        if(!StringUtils.isEmpty(orderSn)){
            criteria.andOrderSnEqualTo(orderSn);
        }
        if(null != userId && !"".equals(userId)){
            criteria.andUserIdEqualTo(userId);
        }
        //票据信息 invoiceType  的 1个人 2公司 3增值
        if(StringUtils.isNotEmpty(invoiceType)){
            criteria.andInvoiceTypeEqualTo(invoiceType);
        }
        //example.setOrderByClause(sort + " " + order);
        if(null != defaultInvoiceInt && !"".equals(defaultInvoiceInt)){
            System.out.println("defaultInvoiceInt Service>>>" + defaultInvoiceInt);
            criteria.andDefaultInvoiceEqualTo(defaultInvoiceInt);
        }
        example.setOrderByClause("add_time"+ " " + "desc");
       return orderInvoiceMapper.selectByExampleSelective(example);
    }

    public LitemallOrderInvoice findByPrimaryKey(Integer id){
        return orderInvoiceMapper.selectByPrimaryKey(id);
    }
}
